<template>
    <el-form ref="ruleFormRef" label-position="top" :model="importForm" :rules="formRules" label-width="auto" v-loading="isLoading">
        <el-row :gutter="30">
            <re-col :value='24' :xs='24' :sm='24'>
                <el-form-item prop='file'>
                    <el-upload class="upload-demo" drag 
                    action="/business/project/drawing/v2/upload" 
                     accept=".jpg,.jpeg,.png,"
                     :headers="{
                      Authorization: formatToken(getToken().accessToken)
      }"
                    :auto-upload="false" 
                    :multiple="true"
                    :style="{ width: '100%' }" 
                    :on-change="handleChange"
                     v-model:file-list="uploadFiles">
                    <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                        <div class="el-upload__text">
                            <div>支持扩展名:JPG,JPEG,PNG,BMP</div>
                            <div>大小不超过10M</div>
                            <div>批量上传命名规则:例如"-2#"代表-2楼</div>
                            
                        </div>
                        <template #tip>
                            <div class="el-upload__tip">
                                <!-- jpg/png files with a size less than 500kb -->
                            </div>
                        </template>
                    </el-upload>
                </el-form-item>
            </re-col>
          
        </el-row>
    </el-form>
</template>
<script lang="ts" setup>
import { UploadFilled } from '@element-plus/icons-vue';
import ReCol from "@/components/ReCol";
import { formatToken, getToken } from "@/utils/auth";
import type { FormRules } from "element-plus";

type FormProps = {
    importForm: any,
    isLoading: false
}
const props = withDefaults(defineProps<FormProps>(), {
    importForm: {
        file: null,
        operator: null,
        canal: null,
    },
    isLoading: false
});

const ruleFormRef = ref();
const formRules = reactive(<FormRules>{
    file: [{ required: true, message: '请选择导入文件', trigger: 'blur' },],

});
const uploadFiles = ref<any>([])
const handleChange = (uploadFile, uploadFiles) => {
    console.log('handleChange', uploadFile, uploadFiles);
    let arr = []
    uploadFiles.forEach(element => {
        arr.push(element.raw)
    });
    // console.log('sdsjdsdpfj',uploadFile.raw, arr);
    props.importForm.file = arr
    // props.importForm.file = uploadFile.raw
}




function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>
<style lang="scss" scoped></style>